#!/usr/bin/python
# -*- coding: utf-8 -*-
# @Time: 20-8-6 下午11:43
# @Author: HuangChuQin
# @Site: 
# @File: views.py
# @Software: PyCharm

from django.http import HttpResponse
from django.http import JsonResponse
from django.shortcuts import render
from .service import bao_stock_service as bss


def index(request):
    return render(request, 'common/index.html', {})


def get_stock_info(request, method='list', code=None):

    if method == 'list':
        return stock_info(request)

    if method == 'daily':
        return stock_k_daily(request, code)

    return JsonResponse({
        'flag': False,
        'msg': 'error method for stock'
    })


def stock_info(request):
    fields, data = bss.get_stock_list()
    return render(request, 'stock-info.html', {
        'title': 'A股基本信息',
        'data_list': data,
        'fields': fields
    })


def stock_k_daily(request, code):
    info, data_list, date_list, volumes = bss.get_stock_hist_data(code)
    return render(request, 'stock-k-daily.html', {
        'info': info,
        'data_list': data_list,
        'date_list': date_list,
        'volumes': volumes
    })
